package ec.edu.ups.cidi.siia.plamdep.moduloweb.jms;


import javax.ejb.Stateless;
import javax.jms.*;
import javax.naming.*;


@Stateless
public class ColaAnalisisClient
{
	
	public ColaAnalisisClient()
	{
		
	}
	
public void enviarMensaje(SolicitudAnalisisJMS sol)
{
	try 
	{ 		
			System.out.println("Enviando mensaje a la cola...");
			//Conectarse a la Cola de mensajes
			Context ic = new InitialContext();
			ConnectionFactory cf = (ConnectionFactory)ic.lookup("java:/ConnectionFactory"); 
			Queue queue = (Queue)ic.lookup("queue/plamdepCola"); 
			Connection  connection = cf.createConnection(); 
			Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
			MessageProducer publisher = session.createProducer(queue); 
			connection.start();
			//preparar el mensaje
			ObjectMessage message = session.createObjectMessage();
			message.setObject(sol);
			publisher.send(message);
			session.close();
			connection.close();
			
	 } catch (Exception exc) 
	 { 
		System.out.println("Error al enviar solicitud a la cola..."); 
		 exc.printStackTrace();

	 } 
}
}
